import selectCustom from "./widgets/selectCustom";

export interface Refs {
    theGrid: YvanUI.CtlGrid;
}

export default abstract class View<M,INP> extends YvanUI.BaseModule<M, Refs, INP> {

    query = {
        login_name: '',
    };

    viewResolver(): any {
        return {
            rows: [
                {
                    cols: [
                        {
                            width: "300",
                            view: "text",
                            label: "登录名",
                            changeValueImplete: true,
                            entityName: "query.login_name",
                        },
                        {
                            view: "button",
                            text: "查询",
                            icon: "fa fa-bars",
                            onClick: {
                                type: "function",
                                bind: "click1",
                            },
                        },
                        {
                            view: "button",
                            text: "校验",
                            icon: "fa fa-bars",
                            onClick: {
                                type: "function",
                                bind: "validateClick",
                            },
                        },
                        {}
                    ]
                },
                {
                    view: "grid",
                    ctlName: "theGrid",
                    idField: "user_id",
                    editable: true,
                    pagination: true,
                    collectData: true,
                    pageSize: 20,
                    defautProperties: {
                        login_name: 'mark',
                        ui_style: 'light'
                    },
                    onRowDelete: {
                        type: "function",
                        bind: "onRowDelete"
                    },
                    columns: [
                        {
                            field: "user_id",
                            hidden: true
                        },
                        {
                            title: "操作",
                            width: 100,
                            buttons: [
                                {
                                    text: "详情",
                                    onClick: {
                                        type: "function",
                                        bind: "gridRowDetail"
                                    },
                                },
                                {
                                    text: "删除",
                                    cssType: "danger",
                                    onClick: {
                                        type: "function",
                                        bind: "gridDelete"
                                    },
                                },
                            ],
                        },
                        {
                            field: "login_name",
                            title: "登录名",
                            width: 100,
                            editable: true,
                            editMode: 'search',
                            widget: {
                                content: selectCustom,
                                params: {
                                    a: 1,
                                    b: "2",
                                },
                                bind: {
                                    "duty": "customercode",
                                    "login_name": "customername",
                                },
                            },
                        },
                        {
                            field: "staff_name",
                            title: "职员姓名",
                            width: 100,
                            editable: true,
                            editParams: {
                                required: true,
                                onValidate: {
                                    type: "function",
                                    bind: "nameValidate",
                                },
                                onChange: {
                                    type: "function",
                                    bind: "nameChange",
                                }
                            }
                        },
                        {
                            field: "gender",
                            title: "性别",
                            width: 70,
                            formatter: [
                                { id: "M", text: "男" },
                                { id: "F", text: "女" },
                            ],
                            editable: true,
                            editMode: 'combo'
                        },
                        {
                            field: "duty",
                            title: "职务",
                            width: 100,
                        },
                        {
                            field: "mobile",
                            title: "手机",
                            width: 120,
                            editable: true,
                        },
                        {
                            field: "ui_style",
                            title: "界面风格",
                            width: 100,
                            formatter: [
                                { id: "light", text: "浅色风格" },
                                { id: "dark", text: "暗色风格" },
                            ],
                            editable: true,
                            editMode: 'combo'
                        },
                        {
                            field: "login_count",
                            title: "登录次数",
                            width: 90,
                            align: "right",
                            editable: true,
                            editMode: 'number',
                            editParams: {
                                precision: 2
                            }
                        },
                        {
                            field: "last_login_time",
                            title: "最后登录时间",
                            width: 160,
                            formatter: "fmtDate",
                            editable: true,
                            editMode: "datetime"
                        },
                        {
                            field: "user_state",
                            title: "是否锁定",
                            width: 100,
                            formatter: [
                                { id: "0", text: "锁定" },
                                { id: "1", text: "正常" },
                            ],
                            onStyle({ value: e }) {
                                if (e == "1") {
                                    return { color: 'green' }
                                }
                                return { color: 'red' }
                            },
                            editable: true,
                            editMode: 'combo'
                        },
                        {
                            field: "birthday",
                            title: "生日",
                            width: 100,
                            editable: true,
                        },
                        {
                            field: "create_at",
                            title: "创建时间",
                            width: 160,
                            formatter: "fmtDate",
                        },
                        {
                            field: "update_at",
                            title: "最后更新时间",
                            width: 160,
                            formatter: "fmtDate",
                        },
                    ],
                    dataSource: {
                        type: "Server",
                        method: "/grid/GridService@selectAll",
                        updatePath: "/grid/GridService@updateById",
                        createPath: "/grid/GridService@addUser",
                        deletePath: "/grid/GridService@deleteById",
                        params: {
                            login_name: {$get: 'query.login_name'},
                        },
                        // onBefore(sender: YvanUI.CtlGrid, e:YvanUI.GridOnBeforeArgs) {
                        //     if (!e.requestParam.params.dictCode) {
                        //         e.handle = true;
                        //         e.successCallback([], 0);
                        //     }
                        // },
                        onUpdateBefore(sender: YvanUI.CtlGrid, e: YvanUI.GridOnCUDBeforeArgs) {
                            console.log('onUpdateBefore', e)
                        },
                        onUpdateAfter(sender: YvanUI.CtlGrid, e: any) {
                            console.log('onUpdateAfter', e)
                        },
                        onCreateBefore(sender: YvanUI.CtlGrid, e: YvanUI.GridOnCUDBeforeArgs) {
                            e.handle = true
                            console.log('onCreateBefore', e)
                        },
                        onCreateAfter(sender: YvanUI.CtlGrid, e: any) {
                            console.log('onCreateAfter', e)
                        },
                        onDeleteBefore(sender: YvanUI.CtlGrid, e: YvanUI.GridOnCUDBeforeArgs) {
                            console.log('onDeleteBefore', e)
                        },
                        onDeleteAfter(sender: YvanUI.CtlGrid, e: any) {
                            console.log('onDeleteAfter', e)
                        }
                    }
                },
            ],
        };
    }
}
